import {AxiosRequestConfig} from "axios"
import {objCopyDeep} from 'st-common-core'
import {getAxiosReqData, setAxiosReqData} from 'st-common-req'
import AxiosNamespace from "st-common-req/axios-namespace"

/**
 * 对请求数据中值为 undefined 的字段进行移除处理
 *
 * @param {AxiosRequestConfig} config 请求配置对象
 */
export const reqDataRemoveUndefinedUtil = (config: AxiosRequestConfig) => {
  const reqData = getAxiosReqData(config as AxiosNamespace.AxiosRequestConfig)
  setAxiosReqData(config as AxiosNamespace.AxiosRequestConfig, objCopyDeep({
    origin: reqData,
    isRemoveObjUndefined: true,
  }))
}
